package nix.mall.search.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

public class GlobalExceptionResolver implements HandlerExceptionResolver {

	private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionResolver.class);

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception e) {
		logger.info("进入全局异常处理器...");
		logger.debug("测试handler类型：" + handler.getClass());
		// 控制台打印异常
		e.printStackTrace();
		// 写入日志文件
		logger.error("系统出现异常", e);
		// 发邮件（jmail）
		
		// 发短信
		
		// 展示错误页面
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("message", "出错了，请稍后再试！");
		modelAndView.setViewName("error/exception");
		return modelAndView;
	}

}
